﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Webnet.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class HTMLTools_Test
    {
        public HTMLTools_Test()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetHtmlWidthTest()
        {
            HTMLTools htmlTools = new HTMLTools();
            int width = htmlTools.GetHtmlWidth(@"<p width=""100%"" align=""center""><embed pluginspage=""http://www.adobe.com/go/getflashplayer"" src=""http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/widgia/mini:calculator""  wmode=""transparent"" width=""219"" height=""344"" FlashVars=""color=12111&xheight=344&xwidth=219&mininame=calculator&uri=yourminis%2Fwidgia%2Fmini%3Acalculator&width=209&height=334&"" type=""application/x-shockwave-flash"" allowScriptAccess=""always""></embed><br /><a href=""http://widgia.com"">More widgets here</a></p>",0);
            Assert.AreEqual(219, width);
            width = htmlTools.GetHtmlWidth(@"<div><object width=""480"" height=""332""><param name=""movie"" value=""http://www.dailymotion.com/swf/x255su&related=0""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowScriptAccess"" value=""always""></param><embed src=""http://www.dailymotion.com/swf/x255su&related=0"" type=""application/x-shockwave-flash"" width=""480"" height=""332"" allowfullscreen=""true"" allowscriptaccess=""always""></embed></object><br /><b><a href=""http://www.dailymotion.com/video/x255su_50-cents-pimp-uncensored_music"">50 Cents - P.I.M.P (Uncensored)</a></b><br /><i>envoy&eacute; par <a href=""http://www.dailymotion.com/toto60620"">toto60620</a>. - <a href=""http://www.dailymotion.com/ca-fr/channel/music"">Regardez d'autres vidéos de musique.</a></i></div>", 0);
            Assert.AreEqual(480, width);
            width = htmlTools.GetHtmlWidth(@"<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"" type=""application/x-shockwave-flash"" width=""120px"" height=""203px"" id=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" align=""middle""><param name=""movie"" value=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""/><param name=""quality"" value=""high"" /><param name=""wmode"" value=""transparent"" /><param name=""menu"" value=""false"" /><param name=""flashvars"" value=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /><param name=""allowScriptAccess"" value=""sameDomain"" /> <embed src=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""  name=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97""  width=""120px"" height=""203px"" quality=""high"" menu=""false"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent"" align=""middle""  allowScriptAccess=""sameDomain"" flashvars=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /></object>", 0);
            Assert.AreEqual(120, width);
            width = htmlTools.GetHtmlWidth(@"<script type=""text/javascript"" src=""http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js""></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('4987c999-03e0-446c-a2d7-fd9f9a784914');</script><noscript>Get the <a href=""http://www.widgetbox.com/widget/baby-ticker"">Baby Ticker - The Baby Countdown Pregnancy Ticker</a> wiydget and many other <a href=""http://www.widgetbox.com/"">great free widgets</a> at <a href=""http://www.widgetbox.com"">Widgetbox</a>! Not seeing a widget? (<a href=""http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/"">More info</a>)</noscript>", 0);
            Assert.AreEqual(-1, width);
            width = htmlTools.GetHtmlWidth(@"<script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F%2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishColor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&amp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script>", 0);
            Assert.AreEqual(320, width);
        }

        [TestMethod]
        public void GetHtmlHeightTest()
        {
            HTMLTools htmlTools = new HTMLTools();
            int height = htmlTools.GetHtmlHeight(@"<p width=""100%"" align=""center""><embed pluginspage=""http://www.adobe.com/go/getflashplayer"" src=""http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/widgia/mini:calculator""  wmode=""transparent"" width=""219"" height=""344"" FlashVars=""color=12111&xheight=344&xwidth=219&mininame=calculator&uri=yourminis%2Fwidgia%2Fmini%3Acalculator&width=209&height=334&"" type=""application/x-shockwave-flash"" allowScriptAccess=""always""></embed><br /><a href=""http://widgia.com"">More widgets here</a></p>", 0);
            Assert.AreEqual(344, height);
            height = htmlTools.GetHtmlHeight(@"<div><object width=""480"" height=""332""><param name=""movie"" value=""http://www.dailymotion.com/swf/x255su&related=0""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowScriptAccess"" value=""always""></param><embed src=""http://www.dailymotion.com/swf/x255su&related=0"" type=""application/x-shockwave-flash"" width=""480"" height=""332"" allowfullscreen=""true"" allowscriptaccess=""always""></embed></object><br /><b><a href=""http://www.dailymotion.com/video/x255su_50-cents-pimp-uncensored_music"">50 Cents - P.I.M.P (Uncensored)</a></b><br /><i>envoy&eacute; par <a href=""http://www.dailymotion.com/toto60620"">toto60620</a>. - <a href=""http://www.dailymotion.com/ca-fr/channel/music"">Regardez d'autres vidéos de musique.</a></i></div>", 0);
            Assert.AreEqual(332, height);
            height = htmlTools.GetHtmlHeight(@"<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"" type=""application/x-shockwave-flash"" width=""120px"" height=""203px"" id=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" align=""middle""><param name=""movie"" value=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""/><param name=""quality"" value=""high"" /><param name=""wmode"" value=""transparent"" /><param name=""menu"" value=""false"" /><param name=""flashvars"" value=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /><param name=""allowScriptAccess"" value=""sameDomain"" /> <embed src=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""  name=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97""  width=""120px"" height=""203px"" quality=""high"" menu=""false"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent"" align=""middle""  allowScriptAccess=""sameDomain"" flashvars=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /></object>", 0);
            Assert.AreEqual(203, height);
            height = htmlTools.GetHtmlHeight(@"<script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F%2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishColor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&amp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script>", 0);
            Assert.AreEqual(200, height);
            height = htmlTools.GetHtmlHeight(@"@<html><head><style>html, body {  height: 100%;  overflow: hidden;}</style></head><body bgcolor=""#0F0F0F"" leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0""><script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F

%2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishC

olor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&a

mp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script></body><html/>", 0);
            Assert.AreEqual(200, height);
        }
    }
}
